home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
bbs
/
pad321.zip
/
PHONE.MH
< prev
next >
Wrap
Text File
|
1996-08-21
|
3KB
|
99 lines
#ifndef __PHONE_MH
#define __PHONE_MH
#ifndef __SETTINGS_MH
#include "settings.mh"
#endif
#ifndef __IN_MH
#include "in.mh"
#endif
#ifndef __STRIPNUM_MH
#include "stripnum.mh"
#endif
// Global variables
int validPhone (Ref string: newPhoneNum) {
int: phoneLen, num_phone_len;
num_phone_len := countChar (str_phone_format,'#');
phoneLen := stripNonNumeric (newPhoneNum);
if (phoneLen = num_phone_len - strlen (str_assume_phone_pfx)) {
newPhoneNum := str_assume_phone_pfx + newPhoneNum;
return True;
};
return (phoneLen = num_phone_len);
}
int getPhone (string: message, Ref string: phoneNum) {
int: phoneLen;
for (;;) {
print (message + "[" + str_phone_format + "]: ");
input_str_ani (phoneNum);
phoneLen := stripNonNumeric (phoneNum);
if (phoneLen = 0) return False; // If no phone number entered, cancel
if (validPhone (phoneNum)) return True;
print (str_bad_phone_number);
};
return True;
}
void beautifyPhone (string: parsedPhone, Ref string: result) {
int: formatPos, phonePos, resultPos;
string: format;
format := str_phone_format;
result := "";
if (validPhone (parsedPhone) = 0) return;
phonePos := 1;
resultPos := 1;
for (formatPos := 1; formatPos <= strlen (str_phone_format); formatPos := formatPos + 1) {
if (format [formatPos] = '#') {
result [resultPos] := parsedPhone [phonePos];
phonePos := phonePos + 1;
resultPos := resultPos + 1;
}
else {
result [resultPos] := format [formatPos];
resultPos := resultPos + 1;
};
};
}
string getNewPhoneNumber (string: oldPhone) {
string: parsedPhone, prettyPhone, tempPhone;
char: key;
parsedPhone := oldPhone;
if (validPhone (parsedPhone) = False) {
if (getPhone (str_change_phone, parsedPhone) = 0)
return "";
};
do {
beautifyPhone (parsedPhone,prettyPhone);
key := input_list_ani ("Ynq\r", str_press_ynq,
str_check_phone1 + prettyPhone + str_check_phone2);
if (key = '\r') key := 'Y';
if (key = 'N') {
if (getPhone (str_change_phone, tempPhone) > 0) parsedPhone := tempPhone;
};
if (key = 'Q') return "";
} while (key <> 'Y');
return prettyPhone;
}
string guessDataPhone () {
string: parsedPhone;
parsedPhone := usr.dataphone;
if (stripNonNumeric (parsedPhone) = 0) {
parsedPhone := usr.phone;
stripNonNumeric (parsedPhone);
};
return parsedPhone;
}
#endif